<template>
	<view class="content">
		<view class="wid100 bacFFF">
			<view class="wid100 dis disAl" style="height: 100rpx;">
				<view class="wid90 mar dis disAl disJuC borRad40 hei60"style="background: #F3F1F1;">
					<view class="dis disJuC" style="width: 13%;">
						<uni-icons type="search" size="35rpx" color="#AFB6B1"></uni-icons>
					</view>
					<input class="wid85 foSi20" v-model="sousuo" @input="sousuoInput" 
						placeholder="输入需要搜索的订单" placeholder-style="color: #AFB6B1;"/>
				</view>
			</view>
			<view class="wid100 mar dis mar-top10">
				<view class="wid50" style="border: 1rpx solid #BFBFBF;height: 98rpx;" @click="xuanClick(0)">
					<view class="wid100 dis disAl disJuC fowe600 foSi40" 
					style="height: 94rpx;" :style="xuan == 0?'color: #37BCC3;':'color: #A3A4A4;'">洗护订单</view>
					<view style="height: 4rpx;" :style="xuan == 0?'background-color: #37BCC3;':'background-color: #fff;'"></view>
				</view>
				<view class="wid50" style="border: 1rpx solid #BFBFBF;height: 98rpx;" @click="xuanClick(1)">
					<view class="wid100 dis disAl disJuC fowe600 foSi40" 
					style="height: 94rpx;" :style="xuan == 1?'color: #37BCC3;':'color: #A3A4A4;'">商城订单</view>
					<view style="height: 4rpx;" :style="xuan == 1?'background-color: #37BCC3;':'background-color: #fff;'"></view>
				</view>
			</view>
		</view>
		<scroll-view style="height: calc(100vh - 302rpx);" class="wid100" scroll-y="true" @scrolltolower="lower">
			<view v-if="list.length == 0" class="wid90 mar fowe800 foSi35 mar-top30">
				<view style="height: 50rpx;"></view>
				<view class="dis disJuC">
					<image src="../../static/zanwu2.png" style="width: 400rpx;height: 300rpx;"></image>
				</view>
				<view class="textCen mar-top20" style="color: #868686;">暂无数据</view>
			</view>
			<block v-for="(item,index) in list" :key="index">
				<view style="height: 1rpx;"></view>
				<view class="wid90 mar bacFFF borRad20 mar-top30" @click="tiaozhuan('/pages/shop/particulars',item.id)"
					style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);">
					<view class="wid90 mar dis disAl disJuB" style="height: 96rpx;">
						<view class="dis disAl">
							<image src="../../static/shangjia_icon.png" style="width: 39rpx;height: 35rpx;"></image>
							<view class="foSi35 fowe800 mar-left20">{{item.gasstation.name}}</view>
						</view>
						<view v-if="item.status == 0 " class="fowe800 foSi30" style="color: #FF0000;">待支付</view>
						<view v-if="item.status == 1" class="fowe800 foSi30" style="color: #388E3C;">已支付</view>
						<view v-if="item.status == 2 && item.collect_clerk_id == 0" class="fowe800 foSi30" style="color: #E040FB;">待接单</view>
						<view v-if="item.status == 2 && item.collect_clerk_id != 0" class="fowe800 foSi30" style="color: #536DFE;">待收衣</view>
						<view v-if="item.status == 3" class="fowe800 foSi30" style="color: #FBC02D;">清洗中</view>
						<view v-if="item.status == 4" class="fowe800 foSi30" style="color: #FFEB3B;">配送中</view>
						<view v-if="item.status == 5" class="fowe800 foSi30" style="color: #F57C00;">代发货</view>
						<view v-if="item.status == 6" class="fowe800 foSi30" style="color: #37BCC3;">待收货</view>
						<view v-if="item.status == 7" class="fowe800 foSi30" style="color: #1976D2;">已完成</view>
						<view v-if="item.status == 8" class="fowe800 foSi30" style="color: #9E9E9E;">已取消</view>
						<view v-if="item.status == 9" class="fowe800 foSi30" style="color: #FFEB3B;">申请退款</view>
						<view v-if="item.status == 10" class="fowe800 foSi30" style="color: #388E3C;">退款成功</view>
						<view v-if="item.status == 11" class="fowe800 foSi30" style="color: #FF4081;">退款失败</view>
					</view>
					<view class="wid100" style="border-bottom: 1rpx dashed #E1DFDF;"></view>
					<view v-if="item.goods_info" class="wid90 mar" style="padding: 25rpx 0;">
						<block v-for="(item1,index1) in JSON.parse(item.goods_info)" :key="index1">
							<view class="dis disAl ">
								<view class="wid25" style="height: 115rpx;">
									<image :src="url+item1.goods_pic" class="hei100" style="width: 115rpx;"></image>
								</view>
								<view style="width: 75%;">
									<view class="mar-top30 dis disAl disJuB foSi25" style="color: #A8AAAA;">
										<view class="foSi25 fowe600" style="width:75%">{{item1.goods_name}}</view>
										<view v-if="item.status == 2 && item.collect_clerk_id == 0" class="" @click.stop="qiang(item.id)" style="color: #fff; background: #b8b800; width: 20%; text-align:center; height: 40rpx; line-height: 40rpx; border-radius: 20rpx;">
											抢单
										</view>
									</view>
									<view class="mar-top30 dis disAl disJuB foSi25" style="color: #A8AAAA;">
										<view>×{{item1.nums}}</view>
										<view>¥{{item1.money}}</view>
									</view>
								</view>
							</view>
							<view class="hei20"></view>
						</block>
						<view class="dis disAl disJuB foSi20">
							<view style="color: #A8AAAA;">{{ item.createtime }}</view>
							<view class="dis disAl">
								<view style="color: #A8AAAA;">共{{ item.goods_info_nums }}件</view>
								<view class="mar-left10">实付款：¥{{ item.pay_amount }}</view>
							</view>
						</view>
					</view>
				</view>
			</block>
			<view style="height: 50rpx;"></view>
		</scroll-view>
		<view class="shuaxin" @click="gengxin">
			刷新
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				// timer: null,
				sousuo: '',
				list: [],
				last_page: 0,
				page: 1,
				xuan: 0,
			}
		},
		onLoad(option) {
			this.getList()
		},
		onShow() {},
		methods: {
			qiang(id){
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_pay_clerk_order_qiang',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						id:id,
						collect_clerk_id:uni.getStorageSync('yuan_userinfo').id
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							uni.showToast({
								title: result.msg,
								icon: 'success',    //将值设置为 success 或者 ''
								duration: 2000    //持续时间为 2秒
							})
							that.gengxin()
						}
					}
				})
			},
			gengxin(){
				this.list = []
				this.page = 1
				this.getList()
			},
			sousuoInput: function(event) {
				var that = this
				// if (that.timer !== null) clearTimeout(that.timer)
				// that.timer = setTimeout(() => {
				that.sousuo = event.target.value
				console.log(that.sousuo)
				that.getList()
				// }, 500)
			},
			open(){
				// 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ，type 属性将失效 ，仅支持 ['top','left','bottom','right','center']
				this.$refs.popup.open()
			},
			close() {
				this.$refs.popup.close()
			},
			xuanClick(index){
				if(this.xuan != index){
					this.xuan = index
					this.list = []
					this.page = 1
					this.getList()
				}
			},
			xiang(item) {
				if (item.status == 1) {
					this.tiaozhuan('/pages/order/particulars?id=' + item.id)
				}
			},
			getList() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_pay_clerk_order_lists',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						search:that.sousuo,
						status: '',
						order_type: that.xuan,
						gas_station_id: uni.getStorageSync('jiaId'),
						page: that.page,
						limit: 10,
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							that.last_page = result.data.last_page
							
							for(var i =0;i<result.data.data.length;i++){
								var goods_info = JSON.parse(result.data.data[i].goods_info);
								var num = 0;
								for(var a = 0; a<goods_info.length;a++){
									num += goods_info[a].nums
								}
								result.data.data[i].goods_info_nums=num; //
							}
							
							if(that.page == 1){
								that.list = result.data.data
							}else{
								that.list = that.list.concat(result.data.data)
							}
						}
					}
				})
			},
			lower(e) {
				if (this.last_page > this.page) {
					this.page++
					this.getList()
				}
			},
			tiaozhuan(url,id) {
				url = url+'?id='+id
				if(this.xuan == 1){
					url = '/pages/shop/particulars2'+'?id='+id
				}
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.content {
		background: #F8F9FD;
		min-height: 100vh;
	}
	.butt1{
		width: 156rpx;
		height: 50rpx;
		border: 1px solid #7D7D7D;
		color: #898989;
	}
	.butt2{
		width: 156rpx;
		height: 50rpx;
		background: #37BCC3;
	}
	.butt3{
		width: 156rpx;
		height: 50rpx;
		background: #FF0000;
	}
	.butt4{
		width: 136rpx;
		height: 46rpx;
		border: 1rpx solid #37BCC3;
		color: #37BCC3;
	}
	.butt5{
		width: 136rpx;
		height: 46rpx;
		background: #37BCC3;
	}
	.shuaxin{
		width: 100%;
		height: 120rpx;
		line-height: 80rpx;
		text-align: center;
		background-color: #37BCC3;
		color: #fff;
		font-size: 40rpx;
		position: absolute;
		bottom: 0;
		left: 0;
	}
</style>